package com.tracesystem.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tracesystem.commons.Result;
import com.tracesystem.controller.Info.AllTypePageInfo;
import com.tracesystem.controller.form.*;
import com.tracesystem.dao.IssueTypeDao;
import com.tracesystem.model.IssueType;
import com.tracesystem.service.IssueTypeService;
import com.tracesystem.util.WoniuCopyUtil;
import com.tracesystem.util.exception.IssueTypeException;
import com.tracesystem.util.exception.code.IssueTypeExceptionCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Martin
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/issueType")
@Api(tags = "缺陷分类操作相关接口 如更新、新增、删除、查询")
public class IssueTypeController {

    /**
     * 缺陷分类业务层对象
     */
    @Resource
    private IssueTypeService issueTypeService;

    /**
     * 缺陷分类实现层对象
     */
    @Resource
    private IssueTypeDao issueTypeDao;

    /**
     * 添加缺陷分类项
     * @param addTypeForm
     * @return
     */
    @ApiOperation("新增缺陷分类")
    @PostMapping("/addType")
    public Result<?> addType(@Valid @RequestBody AddTypeForm addTypeForm){
        return issueTypeService.insertType(addTypeForm);
    }

    /**
     * 删除缺陷分类项
     * @param removeTypeForm
     * @return
     */
    @ApiOperation("删除缺陷分类")
    @PostMapping("/removeType")
    public Result<?> removeType(@RequestBody RemoveTypeForm removeTypeForm){
        return issueTypeService.delectType(removeTypeForm);
    }

    /**
     * 批量删除缺陷分类项
     * @param removeTypeListForm
     * @return
     */
    @ApiOperation("批量删除缺陷分类")
    @PostMapping("/removeTypeList")
    public Result<?> removeTypeList(@RequestBody RemoveTypeListForm removeTypeListForm){
        return issueTypeService.delectTypeList(removeTypeListForm);
    }

    /**
     * 修改缺陷分类
     * @param renewalTypeDescForm
     * @return
     */
    @ApiOperation("修改缺陷分类")
    @PostMapping("/renewalTypeDesc")
    public Result<?> renewalTypeDesc(@RequestBody RenewalTypeDescForm renewalTypeDescForm){
        return issueTypeService.updateTypeDesc(renewalTypeDescForm);
    }

    /**
     * 修改缺陷分类项
     * @param renewalTypeModuleStateForm
     * @return
     */
    @ApiOperation("修改缺陷状态：禁用/启用")
    @PostMapping("/renewalTypeModuleState")
    public Result<?> renewalTypeModuleState(@RequestBody RenewalTypeModuleStateForm renewalTypeModuleStateForm){
        return issueTypeService.updateModuleState(renewalTypeModuleStateForm);
    }

    /**
     * 模糊查询缺陷分类
     * @param likeTypeListForm
     * @return
     */
    @ApiOperation("模糊查询缺陷分类")
    @PostMapping("/likeTypeList")
    public Result<AllTypePageInfo> likeTypeList(@RequestBody LikeTypeListForm likeTypeListForm){
        return issueTypeService.findPageTypeListByTypeDesc(likeTypeListForm);
    }

    /**
     * 查询所有缺陷分类
     * @param findAllTypeListForm
     * @return
     */
    @ApiOperation("查询所有缺陷分类")
    @PostMapping("/findAllTypeList")
    public Result<AllTypePageInfo> findAllTypeList(@RequestBody FindAllTypeListForm findAllTypeListForm){
        return issueTypeService.getAllTypeList(findAllTypeListForm);
    }
}

